home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH05 / PGM5_8.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-10  |  1.5 KB  |  88 lines

  1. ; Pointers to structures
  2. ; Pointers to arrays of structures
  3. ;
  4. ; Randall Hyde
  5.  
  6.  
  7.         .386            ;Need these two statements so we can
  8.         option    segment:use16    ; use 80386 register set.
  9.  
  10. dseg        segment    para public 'data'
  11.  
  12. ; Sample structure.
  13. ; Note: size is seven bytes.
  14.  
  15. Sample        struct
  16. b        byte    ?
  17. w        word    ?
  18. d        dword    ?
  19. Sample        ends
  20.  
  21.  
  22. ; Some variable declarations:
  23.  
  24. OneSample    Sample    {}
  25. SampleAry    Sample    16 dup ({})
  26.  
  27. ; Pointers to the above
  28.  
  29. OnePtr        word    OneSample    ;A near pointer.
  30. AryPtr        dword    SampleAry
  31.  
  32.  
  33. ; Index into the array:
  34.  
  35. Index        word    8
  36.  
  37. dseg        ends
  38.  
  39.  
  40.  
  41.  
  42.  
  43. ; The following program demonstrates how to access each of the above
  44. ; variables.
  45.  
  46. cseg        segment    para public 'code'
  47.         assume    cs:cseg, ds:dseg
  48.  
  49. Main        proc
  50.         mov    ax, dseg    ;These statements are provided by
  51.         mov    ds, ax        ; shell.asm to initialize the
  52.         mov    es, ax        ; segment register.
  53.  
  54. ; AryPtr^[Index] := OnePtr^
  55.  
  56.  
  57.         mov    si, OnePtr    ;Get pointer to OneSample
  58.         les    bx, AryPtr    ;Get pointer to array of samples
  59.         mov    ax, Index    ;Need index*7
  60.         mov    di, 7
  61.         mul    di
  62.         mov    di, ax
  63.  
  64.         mov    al, ds:[si].Sample.b
  65.         mov    es:[bx][di].Sample.b, al
  66.  
  67.         mov    ax, ds:[si].Sample.w
  68.         mov    es:[bx][di].Sample.w, ax
  69.  
  70.         mov    eax, ds:[si].Sample.d
  71.         mov    es:[bx][di].Sample.d, eax
  72.  
  73.  
  74. Quit:        mov    ah, 4ch        ;Magic number for DOS
  75.         int    21h        ; to tell this program to quit.
  76. Main        endp
  77.  
  78. cseg        ends
  79.  
  80. sseg        segment    para stack 'stack'
  81. stk        byte    1024 dup ("stack   ")
  82. sseg        ends
  83.  
  84. zzzzzzseg    segment    para public 'zzzzzz'
  85. LastBytes    byte    16 dup (?)
  86. zzzzzzseg    ends
  87.         end    Main
  88.